//格式化年月日，显示成年-月-日格式
function formateDate(date) {
  if (date.length > 0) {
    let month = date.substring(4, 6);
    let fundMonth = month < 10 ? month.replace(/^0/, "") : month;
    return (
      date.substring(0, 4) +
      "年" +
      fundMonth.replace(/^0/, "") +
      "月" +
      date.substring(6, 8) +
      "日"
    );
  }else{
    return ""
  }

}

function formateDatePicker(date) {
  return (
    date.substring(0, 4) +
    "-" +
    date.substring(4, 6) +
    "-" +
    date.substring(6, 8)
  );
};
//时间戳转换
function changeStampTime(date) {
  var date = new Date(date);
  var Y = date.getFullYear() + "-";
  var M =
    (date.getMonth() + 1 < 10 ?
      "0" + (date.getMonth() + 1) :
      date.getMonth() + 1) + "-";
  var D =
    (date.getDate() < 10 ? "0" + date.getDate() : date.getDate()) + " ";
  return Y + M + D;
}
//获取近一年的时间
function getPassYearFormatDate() {
  var nowDate = new Date();
  var date = new Date(nowDate);
  date.setDate(date.getDate() - 365);
  var seperator1 = "-";
  var year = date.getFullYear();
  var month = date.getMonth() + 1;
  var strDate = date.getDate();
  if (month >= 1 && month <= 9) {
    month = "0" + month;
  }
  if (strDate >= 0 && strDate <= 9) {
    strDate = "0" + strDate;
  }
  var currentdate = year + seperator1 + month + seperator1 + strDate;
  return currentdate;
}

function formateNullData(para) { // 数据字段为null，改为 ‘暂无数据’
  if (!para) {
    return '暂无数据';
  } else {
    return para
  }
}

function  getNowFormatDate(){
  var date = new Date();
  var seperator1 = "";
  var year = date.getFullYear();
  var month = date.getMonth() + 1;
  var strDate = date.getDate();
  if (month >= 1 && month <= 9) {
      month = "0" + month;
  }
  if (strDate >= 0 && strDate <= 9) {
      strDate = "0" + strDate;
  }
  var currentdate = year + seperator1 + month + seperator1 + strDate;
  return currentdate;
}


export {
  formateDate,
  changeStampTime,
  getPassYearFormatDate,
  formateDatePicker,
  formateNullData,
  getNowFormatDate,
}
